package com.kingsystem.kingteachermarks_backend.controller;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.kingsystem.kingteachermarks_backend.entity.DictQuantify;
import com.kingsystem.kingteachermarks_backend.mapper.DictQuantifyMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.List;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author leiyue_yao
 * @since 2025-05-30
 */
@Controller
@RequestMapping("/dictQuantify")
@CrossOrigin
public class DictQuantifyController {
    @Autowired
    private DictQuantifyMapper dqm;


    @RequestMapping("/getDictQuantifyByParentId")
    @ResponseBody
    public List<DictQuantify> getDictQuantifyByParentId(@RequestParam("parentId") String parentId)
    {
        QueryWrapper<DictQuantify> qw = new QueryWrapper<>();
        if(parentId!=null){
            qw.isNull("parent_id");
        }
        else {
            qw.eq("parent_id", parentId);
        }
        List<DictQuantify> li = dqm.selectList(qw);
        return li;
    }

    @RequestMapping("/getAllDictQuantify")
    @ResponseBody
    public List<DictQuantify> getAllDictQuantify()
    {
        QueryWrapper<DictQuantify> qw = new QueryWrapper<>();
        qw.orderByAsc("sort");
        List<DictQuantify> li = dqm.selectList(qw);
        return li;
    }
}
